package com.ohos.carbon.slice.themes;

import com.ohos.carbon.ResourceTable;
import com.ohos.carbon.model.DemoDataBean;
import com.ohos.carbon.slice.MainAbilitySlice;
import com.ohos.carbon.slice.themes.bottom.AbilitySliceProvider;
import com.ohos.carbon.slice.themes.bottom.BaseAbilitySlice;
import com.ohos.carbon.slice.themes.bottom.MainAbilitySliceWindowsPresenter;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Image;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TabList;
import ohos.agp.components.Text;
import ohos.agp.components.element.ElementScatter;

import java.util.ArrayList;
import java.util.Map;

import static com.ohos.carbon.slice.MainAbilitySlice.pf;
public class WindowsThemesSlice extends BaseAbilitySlice implements AbilitySliceProvider {
    private Image back_button;
    private Text text_title, text;
    private ListContainer listContainer;
    private ArrayList<DemoDataBean> mList;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_windows_themes);

        initView();

        new MainAbilitySliceWindowsPresenter(this);
        TabList tabList = (TabList) findComponentById(ResourceTable.Id_tab_list);
        TabList.Tab tab1 = tabList.new Tab(getContext());
        TabList.Tab tab2 = tabList.new Tab(getContext());
        TabList.Tab tab3 = tabList.new Tab(getContext());
        tab1.setText("RECENT");
        tab2.setText("FAVOURITES");
        tab3.setText("OTHER");
        tabList.addTab(tab1);
        tabList.addTab(tab2);
        tabList.addTab(tab3);

        //tabList.setTabLength(350); // 设置Tab的宽度
        //tabList.setTabMargin(35); // 设置两个Tab之间的间距

        MainAbilitySlice.all = (Map<String, Integer>) pf.getAll();
        if (MainAbilitySlice.all.size() != 0){
            if (MainAbilitySlice.all.containsKey("Windows Theme")) {
                for (Map.Entry<String, Integer> entry : MainAbilitySlice.all.entrySet()) {
                    if (entry.getKey().equals("Windows Theme")) {
                        int integer = entry.getValue();
                        integer++;
                        pf.putInt("Windows Theme", integer);
                        pf.flushSync();
                    }
                }
            }else {
                pf.putInt("Windows Theme", 1);
                pf.flushSync();
            }
        }else {
            pf.putInt("Windows Theme", 1);
            pf.flushSync();
        }
    }
    private void initView() {
        back_button = (Image) findComponentById(ResourceTable.Id_back_button);
        text_title = (Text) findComponentById(ResourceTable.Id_title_text);
        text_title.setText("Windows Theme");
//        text = (Text) findComponentById(ResourceTable.Id_text);
//        text.setText(ResourceTable.String_text);
        //listContainer = (ListContainer) findComponentById(ResourceTable.Id_listview);
        back_button.setImageElement(ElementScatter.getInstance(getContext()).parse(ResourceTable.Graphic_carbon_uparrow_white));
        //listContainer.setItemProvider(new ComponentImageProvider(mList,getContext()));
        back_button.setClickedListener(component -> onBackPressed());
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
